<?php
require_once 'Zend/Controller/Action.php';
require_once 'Translator/User.php';

/**
 * Base class for all controllers of this program.
 */
class Translator_Controller extends Zend_Controller_Action
{
	/**
	 * @var Translator_User
	 */
	protected $user;

	/**
	 * Initialize authentification and everything else we gonna need.
	 *
	 * @see Zend_Controller_Action::init()
	 */
	function init() {
		$this->user = new Translator_User();
		Zend_Registry::set('user', $this->user);

		$this->view->messages = $this->_helper->FlashMessenger->getMessages();
	}
	
	/**
	 * Helper to protect areas for administrators only.
	 */
	protected function requireAdmin() {
		if(!$this->user->isAdministrator()) {
			$this->_helper->FlashMessenger('Please sign in.');
			$this->_helper->Redirector('signin', 'user');
		}
	}
	
	/**
	 * Helper to protect areas for authenticated users only.
	 */
	protected function requireAuthenticated() {
		if(!$this->user->isAuthenticated()) {
			$this->_helper->FlashMessenger('Please sign in.');
			$this->_helper->Redirector('signin', 'user');
		}
	}
}